Mark Bramel identified problems with NG Topo! only [A-Z][0-9] are allowed
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 10 Mar 2004 18:35:00 +0000 (18:35 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 10 Mar 2004 18:35:00 +0000 (18:35 +0000)
in waypoint names.

gpsbabel/mkshort.c
gpsbabel/tpg.c

index a6a87727dbcd3070e43550d3d748d55b45d4a3f1..7b653eb27c09d0620565f736eb87c8a7482c4884 100644 (file)
@@ -276,9 +276,6 @@ mkshort(void *h, const char *istring)
                cp = ostring;
                for (i=0;i<l;i++) {
                        if (!isspace(tstring[i])) {
-                               if (hdl->mustupper) {
-                                       tstring[i] = toupper(tstring[i]);
-                               }
                                *cp++ = tstring[i];
                        }
                }
@@ -286,6 +283,11 @@ mkshort(void *h, const char *istring)
                *cp = 0;
        }
 
+       if (hdl->mustupper) {
+               for (tstring = ostring; *tstring; tstring++) {
+                       *tstring = toupper(*tstring);
+               }
+       }
        /*
         * Eliminate chars on the blacklist.
         * Characters that aren't ASCII are never OK.
@@ -343,7 +345,6 @@ mkshort(void *h, const char *istring)
                strcpy(&ostring[hdl->target_len] - strlen(np), np);
        }
 
-
        if (hdl->must_uniq) {
                return mkshort_add_to_list(hdl, ostring);
        }
index f8766f4231f949e4d8f7f782fe2eecd349951350..d62a436471941ab5db88fd71b23fa05493e3461f 100644 (file)
@@ -202,9 +202,10 @@ tpg_waypt_pr(const waypoint *wpt)
        double amt;
        short int elev;
        char tbuf[64];
-       char c;
+       char c,ocount;
        char *shortname;
        char *description;
+       int i;
 
         /* these unknown 4 are probably point properties (color, icon, etc..) */
        unsigned char unknown4[] = { 0x78, 0x56, 0x34, 0x12 }; 
@@ -262,10 +263,27 @@ tpg_waypt_pr(const waypoint *wpt)
 
         /* 1 bytes stringsize for shortname */
         c = strlen(shortname);
-        fwrite(&c, 1, 1, tpg_file_out);
-        
-        /* shortname */
-        fwrite(shortname, 1, c, tpg_file_out);
+        ocount = 0;
+       /* 
+        * It's reported the only legal characters are upper case
+        * A-Z and 0-9.  Wow.   We have to make two passes: one to
+        * count and one to output.
+        */
+       for (i = 0; i < c; i++) {
+               char oc = toupper(shortname[i]);
+               if (isalnum(oc) || oc == ' ') {
+                       ocount++;
+               }
+       }
+
+        fwrite(&ocount, 1, 1, tpg_file_out);
+
+       for (i = 0; i < c; i++) {
+               char oc = toupper(shortname[i]);
+               if (isalnum(oc) || oc == ' ') {
+                       fputc(oc, tpg_file_out);
+               }
+       }
 
         /* 8 bytes - longitude */
         tpg_fwrite_double(lon, tpg_file_out);
@@ -316,6 +334,7 @@ tpg_write(void)
         if (global_opts.synthesize_shortnames) {
             setshort_length(mkshort_handle, 32);
             setshort_whitespace_ok(mkshort_handle, 1);
+            setshort_mustupper(mkshort_handle, 1);
         }
 
         if (s > MAXTPGOUTPUTPINS) {